using System;
using SMS.SMPPClient.PDU;

namespace SMS.SMPPClient.Common
{
    public class BitBuilder
    {
        // Fields
        private bool[] _Bits;

        // Methods
        public BitBuilder()
        {
            this._Bits = new bool[8];
        }

        public BitBuilder(byte value)
        {
            this._Bits = new bool[8];
            this.Value = value;
        }

        // Properties
        public bool Bit0
        {
            get { return this._Bits[0]; }
            set { this._Bits[0] = value; }
        }

        public bool Bit1
        {
            get { return this._Bits[1]; }
            set { this._Bits[1] = value; }
        }

        public bool Bit2
        {
            get { return this._Bits[2]; }
            set { this._Bits[2] = value; }
        }

        public bool Bit3
        {
            get { return this._Bits[3]; }
            set { this._Bits[3] = value; }
        }

        public bool Bit4
        {
            get { return this._Bits[4]; }
            set { this._Bits[4] = value; }
        }

        public bool Bit5
        {
            get { return this._Bits[5]; }
            set { this._Bits[5] = value; }
        }

        public bool Bit6
        {
            get { return this._Bits[6]; }
            set { this._Bits[6] = value; }
        }

        public bool Bit7
        {
            get { return this._Bits[7]; }
            set { this._Bits[7] = value; }
        }

        public bool[] Bits
        {
            get { return this._Bits; }
            set { this._Bits = value; }
        }

        public byte Value
        {
            get
            {
                byte num2 = 0;
                for (byte i = 0; i < 8; i = (byte)(i + 1))
                {
                    num2 = (byte)(num2 + Convert.ToByte((double)(SmppConverter.BooleanToByte(this._Bits[i]) * Math.Pow(2.0, (double)i))));
                }
                return num2;
            }
            set
            {
                byte num2 = 1;
                for (byte i = 0; i < 8; i = (byte)(i + 1))
                {
                    this._Bits[i] = (value & num2) > 0;
                    num2 = (byte)(num2 * 2);
                }
            }
        }
    }
}

